<template>
  <div>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        :immediate-check="flag"
      >
        <!-- <van-cell  :title="item" /> -->
        <van-card
          @click="goDetail(item.id)"
          v-for="item in arr"
          :key="item.id"
          :num="item.num"
          :price="item.price"
          desc="这个一个商品"
          :title="item.tit"
          :thumb="item.img"
        />
      </van-list>
    </van-pull-refresh>
    <div style="height:40px"></div>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
export default {
  data() {
    return {
      flag:false,
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  mounted() {
    this.getlist();
  },
  computed: {
    ...mapState(["arr"]),
  },
  methods: {
    ...mapActions(["getlist"]),
    goDetail (id) {
        this.$router.push("/detail/" + id)
    },
    onLoad () {
      setTimeout(() => {
        if (this.refreshing) {
          // 下拉刷新的逻辑
          this.getlist();
          this.refreshing = false;
        }

        this.getlist("up");
        this.loading = false;

        if (this.arr.length >= 50) {
          this.finished = true;
        }
      }, 1000);
    },
    onRefresh() {
      // 清空列表数据
      this.finished = false;

      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
  },
};
</script>

<style>
</style>